#pragma once

#include <FTPSession.h>
#include <TcpServer.h>

class FTPServer {
	using SessionPtr = std::shared_ptr<FTPSession>;
public:
	FTPServer(const std::string& ip, int port = 2121);

	void onMessage(std::shared_ptr<TcpConnection> conn, Buffer& inBuffer);

	void onWriteComplete(std::shared_ptr<TcpConnection> conn);

	void onConnectionEstablished(std::shared_ptr<TcpConnection> conn);

	void onCloseConnection(std::shared_ptr<TcpConnection> conn);

	void start();

private:
	std::mutex sessionMapLock_;
	std::unique_ptr<TcpServer> server_;
	std::atomic<bool> started_;
	std::unordered_map<std::string, std::shared_ptr<FTPSession>> sessionMap_;
};